package com.headline.repository;

import com.headline.model.UserEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


/**
 * Created by Administrator on 2016/10/11.
 */

@Repository
public interface UserRepository extends JpaRepository<UserEntity, Integer> {

    @Modifying      // 说明该方法是修改操作
    @Transactional  // 说明该方法是事务性操作
    // 定义查询
    // @Param注解用于提取参数
    @Query("update UserEntity  set nickname=:qNickname,password=:qPassword where id=:qId")
    void updateUser(@Param("qNickname") String nickname,
                    @Param("qPassword") String password, @Param("qId") Integer id);

//    @Query(value = " select id,nickname,password from UserEntity  us where us.nickname=:qNickname and us.password=:qPassword")
//    Object checkLogin(@Param("qNickname") String nickname, @Param("qPassword") String password);

    //验证用户登陆
    @Query(value = "select id,nickname,password from UserEntity   where nickname=:qNickname and password=:qPassword")
    List<UserEntity> findByNicknameAdnPassword(@Param("qNickname") String nickname, @Param("qPassword") String password);


}


